package com.wbcs.config.component.application.jsphtml;

import com.wbcs.config.component.AbsComponentConfigBean;
import com.wbcs.config.component.IComponentConfigBean;
import com.wbcs.config.component.application.IApplicationConfigBean;
import com.wbcs.config.component.application.report.ReportBean;
import com.wbcs.config.component.container.AbsContainerConfigBean;
import com.wbcs.config.component.container.panel.TabsPanelBean;
import com.wbcs.config.dataexport.DataExportsConfigBean;
import com.wbcs.config.dataexport.PDFExportBean;
import com.wbcs.config.print.AbsPrintProviderConfigBean;
import com.wbcs.config.xml.XmlElementBean;
import com.wbcs.exception.WbcsConfigLoadingException;

public abstract class AbsJspHtmlComponentBean extends AbsComponentConfigBean implements IApplicationConfigBean
{
    private String printwidth;
    
    protected String belongto;

    protected IComponentConfigBean belongToCcbean;
    
    public AbsJspHtmlComponentBean(AbsContainerConfigBean parentContainer)
    {
        super(parentContainer);
    }

    public IComponentConfigBean getBelongToCcbean()
    {
        return belongToCcbean;
    }

    public void setBelongToCcbean(IComponentConfigBean belongToCcbean)
    {
        this.belongToCcbean=belongToCcbean;
    }
    
    public IComponentConfigBean getConfigBeanWithValidParentTitle()
    {
        if(this.parenttitle!=null&&!this.parenttitle.trim().equals("")) return this;
        return null;
    }
    
    public void loadExtendConfig(XmlElementBean eleJspHtml,AbsContainerConfigBean parentConfigBean)
    {
        this.belongto=eleJspHtml.attributeValue("belongto");
    }
    //<html/>、<jsp/>不能配置打印、数据导出等功能，所以下面全部置成null
    @Override
	public void setDataExportsBean(DataExportsConfigBean dataExportsBean)
    {
        super.setDataExportsBean(null);
    }

    @Override
	public void setPdfPrintBean(PDFExportBean pdfPrintBean)
    {
        super.setPdfPrintBean(null);
    }

    @Override
	public void setPrintBean(AbsPrintProviderConfigBean printBean)
    {
        super.setPrintBean(null);
    }

    public String getPrintwidth()
    {
        return printwidth;
    }

    public void setPrintwidth(String printwidth)
    {
        this.printwidth=printwidth;
    }

    @Override
	public void doPostLoad()
    {
        if(belongto!=null&&!belongto.trim().equals(""))
        {
            belongToCcbean=this.getPageBean().getChildComponentBean(belongto,true);
            if(belongToCcbean==null)
            {
                throw new WbcsConfigLoadingException("加载组件"+this.getPath()+"失败，其belongto属性配置的附属组件"+this.belongto+"不存在");
            }
            if(!(belongToCcbean instanceof ReportBean)&&!(belongToCcbean instanceof AbsContainerConfigBean))
            {
                throw new WbcsConfigLoadingException("加载组件"+this.getPath()+"失败，其belongto属性配置的附属组件"+this.belongto+"不是容器或报表组件");
            }
            String ccbeanRefreshid=belongToCcbean.getRefreshid();
            if(ccbeanRefreshid==null||ccbeanRefreshid.trim().equals("")) ccbeanRefreshid=this.belongToCcbean.getId();
            ccbeanRefreshid=this.getPageBean().getCommonRefreshIdOfComponents(ccbeanRefreshid,this.id);
            belongToCcbean.setRefreshid(ccbeanRefreshid);
            AbsContainerConfigBean parentContainerBean=belongToCcbean.getParentContainer();
            TabsPanelBean tpbeanTmp;
            while(parentContainerBean!=null)
            {
                if(parentContainerBean instanceof TabsPanelBean)
                {
                    tpbeanTmp=(TabsPanelBean)parentContainerBean;
                    if(tpbeanTmp.getChildComponentBean(this.id,true)==null||!tpbeanTmp.isInSameTabItem(belongToCcbean,this))
                    {
                        tpbeanTmp.setAsyn(false);
                    }
                }
                if(parentContainerBean.getChildComponentBean(this.id,true)!=null) break;//当前容器已经是它们的父容器了，则不用再向上找父<tabpanel/>了
                parentContainerBean=parentContainerBean.getParentContainer();
            }
        }
    }
}

